import { asyncRoutes } from '@/router'

const state = {
  routers: []
}
const mutations = {
  addRouter(state, list) {
    state.routers = list
  }
}
const actions = {
  addRouter(store, userInfo) {
    const {
      roles
    } = userInfo
    const routers = asyncRoutes.filter((v) => roles.menus.includes(v.name))
    store.commit('addRouter', routers)
    return routers
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
